package com.bite.demo.model;

import com.bite.demo.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T>{
    private int code;
    private String errMsg;
    private T data;

    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        result.setErrMsg("");
        return result;
    }

    public static <T> Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result fail(String errMsg,T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result fail(int code,String errMsg) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;

    }
    public static <T> Result<T> success2(T data) {
        //用户登录
        Result result = new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setErrMsg("");
        result.setData(data);
        return result;
    }


}
